// // Copyright (c) 2009 All Right Reserved // // Stephen Toub // stoub@microsoft.com // 2009-01-01 // Contains ... using System; using System.Globalization; using System.IO; using System.Text; using JetBrains.Annotations; namespace LargoCommon.Midi { /// A time signature meta event message. [Serializable] public sealed class MetaTimeSignature : MetaEvent { #region Fields /// The meta id for this event. private const byte EventMetaId = 0x58; #endregion #region Constructors /// Initializes a new instance of the MetaTimeSignature class. /// The amount of time before this event. /// Numerator of the time signature. /// Negative power of two, denominator of time signature. /// The number of MIDI clocks per metronome click. /// The number of notated 32-nd notes per MIDI quarter note. public MetaTimeSignature( long deltaTime, byte numerator, byte denominator, byte midiClocksPerClick, byte numberOfNotated32) : base(deltaTime, EventMetaId) { this.Numerator = numerator; this.Denominator = denominator; this.MidiClocksPerClick = midiClocksPerClick; this.NumberOfNotated32 = numberOfNotated32; } /// Initializes a new instance of the MetaTimeSignature class. /// The amount of time before this event. /// The ID of the meta event. [UsedImplicitly] public MetaTimeSignature(long deltaTime, byte givenMetaEventId) : base(deltaTime, givenMetaEventId) { } #endregion #region Properties /// Gets the numerator for the event. /// General musical property. public byte Numerator { get; } /// Gets the denominator for the event. /// General musical property. public byte Denominator { get; } /// Gets the MIDI clocks per click for the event. /// General musical property. private byte MidiClocksPerClick { get; } /// Gets the number of notated 32 notes per MIDI quarter note for the event. /// General musical property. private byte NumberOfNotated32 { get; } #endregion #region To String /// Generate a string representation of the event. /// A string representation of the event. public override string ToString() { var sb = new StringBuilder(); sb.Append(base.ToString()); sb.Append("\t"); sb.Append("0x"); sb.Append(this.Numerator.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.Denominator.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.MidiClocksPerClick.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.NumberOfNotated32.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); return sb.ToString(); } #endregion #region Methods /// Write the event to the output stream. /// The stream to which the event should be written. public override void Write(Stream outputStream) { if (outputStream == null) { return; } //// Write out the base event information base.Write(outputStream); //// Event data outputStream.WriteByte(0x04); outputStream.WriteByte(this.Numerator); outputStream.WriteByte(this.Denominator); outputStream.WriteByte(this.MidiClocksPerClick); outputStream.WriteByte(this.NumberOfNotated32); } #endregion } }